import Cocoa
import Foundation

// 应用程序入口点
class AppDelegate: NSObject, NSApplicationDelegate {
    var taskbarController: TaskbarController?
    
    func applicationDidFinishLaunching(_ notification: Notification) {
        // 请求辅助功能权限
        requestAccessibilityPermission()
        
        // 初始化任务栏控制器
    let windowManager = WindowManager.shared
    taskbarController = TaskbarController()
    taskbarController?.setWindowManager(windowManager)
        taskbarController?.setupTaskbars()
        
        // 隐藏应用程序图标在Dock中
        NSApp.setActivationPolicy(.accessory)
    }
    
    func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
        return false // 即使关闭所有窗口也不退出应用
    }
    
    private func requestAccessibilityPermission() {
        let options = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: true]
        let accessEnabled = AXIsProcessTrustedWithOptions(options as CFDictionary)
        
        if !accessEnabled {
            // print("需要辅助功能权限才能正常工作")
        }
    }
}

// 程序入口点
let app = NSApplication.shared
let delegate = AppDelegate()
app.delegate = delegate
app.run()